x_length = 100

xpos=x_length*aux_data1(xpos_ch,:);
ypos=2*aux_data1(ypos_ch,:);

vel_fw=[0 diff(aux_data1(fw_ch,:))];
vel_fw(vel_fw>5)=vel_fw(vel_fw>5)-10;
vel_fw(vel_fw<-5)=vel_fw(vel_fw<-5)+10;
vel_fw=ftfil(vel_fw,1000,0,10);

vel_ro=[0 diff(aux_data1(ro_ch,:))];
vel_ro(vel_ro>5)=vel_ro(vel_ro>5)-10;
vel_ro(vel_ro<-5)=vel_ro(vel_ro<-5)+10;
vel_ro=ftfil(vel_ro,1000,0,10);

for xnd = 1:length(aux_data1(10,:))
    if aux_data1(10,xnd)>2.5
       aux_data1(10,xnd)=((aux_data1(10,xnd)-2.5)/2.5*180);
    end
    if aux_data1(10,xnd)<2.5
       aux_data1(10,xnd)=((aux_data1(10,xnd)-2.5)/2.5*180);
    end
end

reward_times=find(diff(round(aux_data1(reward_ch,:)))==5);
nbr_rewards=length(reward_times)

heading_vec_x=smooth2(xpos-x_length*vel_fw.*cos(pi*(aux_data1(ro_ch,:)-2.5)/2.5),10);
heading_vec_y=smooth2(ypos+x_length*vel_fw.*sin(pi*(aux_data1(ro_ch,:)-2.5)/2.5),10);

figure;hist(aux_data1(10,:),100)

for ind=1
    figure, hold on
    t_inds=reward_times(ind)+1500:reward_times(ind+1);
    plot(xpos(t_inds),ypos(t_inds),'linewidth',3);
    for knd=1:100:length(t_inds)
        plot([xpos(t_inds(knd)) heading_vec_x(t_inds(knd))],[ypos(t_inds(knd)) heading_vec_y(t_inds(knd))],'r');
    end
end

figure, subplot(3,2,5)
hold on
for ind=1
    t_inds=reward_times(ind)+1500:reward_times(ind+1);
    plot(xpos(t_inds),ypos(t_inds),'linewidth',3);
    for knd=1:100:length(t_inds)
        plot([xpos(t_inds(knd)) heading_vec_x(t_inds(knd))],[ypos(t_inds(knd)) heading_vec_y(t_inds(knd))],'r');
    end
end
subplot(3,2,3), hist(aux_data1(10,:),100)
subplot(3,2,1), plot(aux_data1(11,:))